/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年5月20日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.lesson3.tree.binarytree.huffmantreecode;

import java.util.Map;

/**
 * @Type Node
 * @Desc
 * @author 52489
 * @date 2019年5月20日
 * @Version V1.0
 */
public class Node implements Comparable<Node> {
    Byte data;
    int weight;
    Node left;
    Node right;

    /**
     * @param data
     * @param weight
     * @param left
     * @param right
     */
    public Node(Byte data, int weight) {
        this.data = data;
        this.weight = weight;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    @Override
    public int compareTo(Node o) {
        return o.weight - this.weight;
    }

    @Override
    public String toString() {
        return "Node [data=" + data + ", weight=" + weight + "]";
    }

    /**
     * 前序遍历
     * 
     * @param codeMap
     */
    public void frontShow(Map<Byte, String> codeMap) {
        System.out.println(weight + " " + data + " " + codeMap.get(data));
        if (left != null) {
            left.frontShow(codeMap);
        }

        if (right != null) {
            right.frontShow(codeMap);
        }
    }
}
